package com.hnas.common.domain;

import java.util.HashMap;
import java.util.Map;

public class DiscountType {
	public static final String DISCOUNT = "0";//打折
	public static final String DERATE = "1";//减免金额
	
	private static Map<String,String> map = new HashMap<String,String>();
	
	static{
		map.put(DISCOUNT, "打折");
		map.put(DERATE, "减免金额");
	}
	
	public static Map<String,String> getMap(){
		return map;
	}

	public static String getShowTypeStr(String type,Long value) {
		if(type == null) return null;
		if(DISCOUNT.equals(type)){
			return value/10.0+"折";
		}else if(DERATE.equals(type)){
			return "减免"+value/100.00+"元";
		}
		return null;
	}

	public static String getTypeStr(String type) {
		if(type == null) return null;
		for(String key : map.keySet()){
			if(key.equals(type)){
				return map.get(key);
			}
		}
		return null;
	}
	
	public static String longToString(Long val,String type){
		if(val == null) return null;
		if(DISCOUNT.equals(type)){
			return Double.valueOf(val/10.0).toString();
		}else if(DERATE.equals(type)){
			return Double.valueOf(val/100.0).toString();
		}
		return null;
	}
	public static Long stringToLong(String val,String type){
		if(val == null) return null;
		if(DISCOUNT.equals(type)){
			return Double.valueOf(Double.valueOf(val)*10).longValue();
		}else if(DERATE.equals(type)){
			return Double.valueOf(Double.valueOf(val)*100).longValue();
		}
		return null;
	}
}
